import fetchPayOrder from '../../yali-sdk/business/order/fetchPayOrder';
import getIn from '../../yali-sdk/utils/getIn';
export const PAY_FAIL = 'PAY_FAIL';
export function wxPay(params, callback) {
    global.ActionDispatcher.execute(fetchPayOrder, params, (status, result) => {
        if (status === 'SUCCESS') {
            wx.requestPayment({
                timeStamp: getIn(result, ['data', 'times']),
                nonceStr: getIn(result, ['data', 'nonce_str']),
                package: getIn(result, ['data', 'prepay_id']),
                signType: 'MD5',
                paySign: getIn(result, ['data', 'sign']),
                success(res) {
                    callback('SUCCESS', res);
                },
                fail(res) {
                    callback(PAY_FAIL, res);
                },
            });
        } else if (status === 'FAIL') {
            callback('FAIL', result);
        }
    });
}
